#include <algorithm>
#include <cassert>
#include <iostream>
#include <unordered_set>
#include <vector>

using namespace std;

class Solution {
public:
    void moveZeroes(vector<int>& nums) {
        int n = nums.size(), left = 0, right = 0;
        while (right < n) {     // 右指针未遍历到底
            if (nums[right]) {  // 如果不为0，则左右指针交换，并且左指针右移
                swap(nums[left], nums[right]);
                ++left;
            }
            ++right;
        }
    }
};

int main() {
    Solution s;

    vector<int> input1{0, 1, 0, 3, 12};
    vector<int> input2{0};
    vector<int> output1{1, 3, 12, 0, 0};
    vector<int> output2{0};

    s.moveZeroes(input1);
    s.moveZeroes(input2);

    assert(input1 == output1);
    assert(input2 == output2);

    return 0;
}